import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JPasswordField;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


public class Group_Layout extends JDialog {

	private final JPanel contentPanel = new JPanel();
	private JTextField uid;
	private JPasswordField pwd;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			Group_Layout dialog = new Group_Layout();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public Group_Layout() {
		setTitle(":: Group Layout ::");
		setBounds(100, 100, 464, 309);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		
		JLabel txtUid = new JLabel("아이디");
		
		uid = new JTextField();
		uid.setColumns(10);
		
		JLabel txtPwd = new JLabel("비밀번호");
		
		JButton loginBtn = new JButton("로그인");
		
		loginBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String muid = uid.getText(); 
				// uid라는 textField에 입력된 문자열을 가져와서 문자열 변수 muid에 저장
				String mpwd = pwd.getText();
				
				if(muid.equals("jwr15") && mpwd.equals("1111"))
					JOptionPane.showMessageDialog(null, "아이디와 비밀번호 일치 됨");
					//아이디와 비밀번호가 일치하면 확인됐다고 다이얼로그 표시
				else if(muid.equals("") || mpwd.equals(""))
					JOptionPane.showMessageDialog(null, "아이디와 비밀번호를 입력해주세요");
					//mid나 mpwd에 입력된 문자열이 빈값이면 입력하라는 대화상자 표시
				else
					JOptionPane.showMessageDialog(null, "실패");
				// 아이디와 비밀번호가 일치하지 않으면 실패라는 다이얼로그 표시
			}		
		});
		
		pwd = new JPasswordField();
		
		JLabel txtReg = new JLabel("사용자 등록");
		
		JLabel txtFind = new JLabel("ID/PW 찾기");
		
		JLabel txtSeparator = new JLabel("|");
		GroupLayout gl_contentPanel = new GroupLayout(contentPanel);
		gl_contentPanel.setHorizontalGroup(
			gl_contentPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addGap(70)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPanel.createSequentialGroup()
							.addGap(19)
							.addComponent(txtReg))
						.addGroup(Alignment.TRAILING, gl_contentPanel.createParallelGroup(Alignment.LEADING)
							.addGroup(gl_contentPanel.createSequentialGroup()
								.addComponent(txtPwd, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
								.addPreferredGap(ComponentPlacement.RELATED))
							.addGroup(Alignment.TRAILING, gl_contentPanel.createSequentialGroup()
								.addComponent(txtUid, GroupLayout.PREFERRED_SIZE, 73, GroupLayout.PREFERRED_SIZE)
								.addGap(10))))
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.TRAILING)
						.addGroup(gl_contentPanel.createSequentialGroup()
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(uid))
						.addGroup(Alignment.LEADING, gl_contentPanel.createSequentialGroup()
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(pwd))
						.addGroup(Alignment.LEADING, gl_contentPanel.createSequentialGroup()
							.addGap(25)
							.addComponent(txtSeparator)
							.addGap(18)
							.addComponent(txtFind)))
					.addGap(18)
					.addComponent(loginBtn)
					.addGap(167))
		);
		gl_contentPanel.setVerticalGroup(
			gl_contentPanel.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPanel.createSequentialGroup()
					.addGap(53)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING)
						.addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING, false)
							.addGroup(Alignment.TRAILING, gl_contentPanel.createSequentialGroup()
								.addComponent(uid, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addPreferredGap(ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
								.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
									.addComponent(pwd, GroupLayout.PREFERRED_SIZE, 18, GroupLayout.PREFERRED_SIZE)
									.addComponent(txtPwd)))
							.addComponent(loginBtn, Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 59, GroupLayout.PREFERRED_SIZE))
						.addComponent(txtUid))
					.addGap(31)
					.addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE)
						.addComponent(txtReg)
						.addComponent(txtSeparator)
						.addComponent(txtFind))
					.addContainerGap(135, Short.MAX_VALUE))
		);
		contentPanel.setLayout(gl_contentPanel);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okBtn = new JButton("확인");
				okBtn.setActionCommand("OK");
				buttonPane.add(okBtn);
				getRootPane().setDefaultButton(okBtn);
			}
		}
	}
}
